package com.example.demo.web;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.ctrip.framework.apollo.Config;
import com.ctrip.framework.apollo.ConfigService;

@RestController
public class RedisController {

	@Value("${spring.redis.host}")
	private String host;
	
	@Value("${spring.redis.port}")
	private String port;
	
	@RequestMapping("/redis")
	public String redis() {
		return host + " : " + port;
	}
	
	@RequestMapping("/list")
	public String list(String namespace, String key) {
		Config config = ConfigService.getConfig(namespace);
//		String someKey = "someKeyFromYmlNamespace";
//		String someDefaultValue = "someDefaultValueForTheKey";
//		String value = config.getProperty(someKey, someDefaultValue);
		if(key != null && ! "".equals(key))
			return config.getProperty(key, null);
		return config.getPropertyNames().toString();
	}
}
